package com.ap.core.validation.message.rules;

import com.ap.core.cxf.jaxb.paymentdetails.TransactionStatusCode;
import com.ap.core.cxf.jaxb.paymentdetails.TxnStatusType;
import com.ap.core.message.managepayment.info.ConfirmPaymentRequestMessageInfo;
import com.ap.core.validation.message.info.MessageValidationInfo;
import com.ap.core.validation.message.info.OriginalInfo;
import com.ap.core.validation.rules.AbstractValidationRule;

/**
 * User:Rohit.Dixit
 * PaymtTimestamp and FasterPaymentsRef data field will have value if the <TxnStatusCode>=Successful in the message
 */
public class ValidTransactionStatusRule extends AbstractValidationRule<MessageValidationInfo<ConfirmPaymentRequestMessageInfo, OriginalInfo>> {

	@Override
	public boolean validate(
			MessageValidationInfo<ConfirmPaymentRequestMessageInfo, OriginalInfo> infoObject) {
		boolean pass = false;
		if(infoObject.getBoundObject().getPaymtDetails().getPaymentStatusInfo().getTxnStatus() == TxnStatusType.AUTHORISED && infoObject.getBoundObject().getPaymtDetails().getPaymentStatusInfo().getTxnStatusCode() == TransactionStatusCode.A_00  && 
				infoObject.getBoundObject().getPaymtDetails().getFasterPaymentsRef() != null && !infoObject.getBoundObject().getPaymtDetails().getFasterPaymentsRef().trim().isEmpty()){
			return true;
		}else if(infoObject.getBoundObject().getPaymtDetails().getPaymentStatusInfo().getTxnStatus() == TxnStatusType.DECLINED && infoObject.getBoundObject().getPaymtDetails().getPaymentStatusInfo().getTxnStatusCode() != TransactionStatusCode.A_00){
			return true;
		}
		return false;
	}

}

